package cn.minsh.lims.eoms.modules.app.service.impl;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.minsh.lims.eoms.common.utils.PageUtils;
import cn.minsh.lims.eoms.common.utils.Query;

import cn.minsh.lims.eoms.modules.app.dao.PlanAgentDao;
import cn.minsh.lims.eoms.modules.app.entity.PlanAgentEntity;
import cn.minsh.lims.eoms.modules.app.service.PlanAgentService;


@Service("planAgentService")
public class PlanAgentServiceImpl extends ServiceImpl<PlanAgentDao, PlanAgentEntity> implements PlanAgentService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<PlanAgentEntity> page = this.page(
                new Query<PlanAgentEntity>().getPage(params),
                new QueryWrapper<PlanAgentEntity>()
        );

        return new PageUtils(page);
    }
    @Override
    public void add(PlanAgentEntity planAgent,Long userId){
        save(planAgent) ;
    }

    @Override
    public void updateBy(PlanAgentEntity planAgent,Long userId){
        updateById(planAgent) ;
    }

    @Override
    public void deleteByTypeAndPlanId(Integer code, Long planId) {
        QueryWrapper<PlanAgentEntity> deleteWrapper = new QueryWrapper<>() ;
        deleteWrapper.eq("type",code) ;
        deleteWrapper.eq("plan_id",planId) ;
        this.remove(deleteWrapper) ;
    }

    @Override
    public List<PlanAgentEntity> listByTypeAndPlanId(Integer code, Long id) {
        QueryWrapper<PlanAgentEntity> wrapper = new QueryWrapper<>() ;
        wrapper.eq("type",code) ;
        wrapper.eq("plan_id",id) ;
        return this.list(wrapper);
    }

    @Override
    public List<PlanAgentEntity> listByType(Integer code) {
        QueryWrapper<PlanAgentEntity> wrapper = new QueryWrapper<>() ;
        wrapper.eq("type",code) ;
        return this.list(wrapper);
    }

    @Override
    public List<PlanAgentEntity> listByTypeAndAgentId(Integer code, Long userId) {
        QueryWrapper<PlanAgentEntity> wrapper = new QueryWrapper<>() ;
        wrapper.eq("type",code) ;
        wrapper.eq("agent_id",userId) ;
        return this.list(wrapper) ;
    }
}